package com.bigdata.demo.controller;

import com.bigdata.demo.client.UserClient;
import com.bigdata.demo.domain.User;
import com.bigdata.demo.service.SendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by root on 2/27/18.
 */
@RestController
@RequestMapping("/api")
public class DemoClass {
    private final Logger logger = LoggerFactory.getLogger(DemoClass.class);

    @Inject
    private UserClient userClient;

    @Autowired
    private SendService service;

    @RequestMapping(value = "/feign/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> findOne(@PathVariable Integer id) {
        User user = new User();
        user = userClient.findById(id);
        return new ResponseEntity<>(user, HttpStatus.OK);
    }

    @RequestMapping(value = "/feign", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> findAll() {
        List<User> list = new ArrayList<User>();
        list = userClient.findAll();
        return new ResponseEntity<>(list, HttpStatus.OK);
    }

    @RequestMapping(value = "/sendMessage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> send(@RequestParam String msg) {
        service.send("f10-spark",msg);
        return new ResponseEntity<>(null, HttpStatus.OK);
    }
}
